﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:local="clr-namespace:NTLib.WPF.Controls"
    xmlns:selector="clr-namespace:NTLib.WPF.Selectors"
    xmlns:conv="clr-namespace:NTLib.WPF.Converters"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <conv:NotConverter x:Key="NotConverter" />
    <conv:EnumValuesConverter x:Key="EnumValuesConverter" />

    <Style x:Key="PropertyViewLabelHeaderStyle" TargetType="TextBlock">
        <Setter Property="Margin" Value="5" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="HorizontalAlignment" Value="Left" />
    </Style>

    <Style x:Key="PropertyViewElementStyle" TargetType="CheckBox">
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="HorizontalAlignment" Value="Left" />
    </Style>

    <Style x:Key="PropertyViewerGridStyle" TargetType="Grid">
        <Setter Property="Margin" Value="0, 5, 0, 0" />
    </Style>
    
    <Style TargetType="{x:Type local:PropertyViewer}">
        <Setter Property="ExposedOnlyTagProperties" Value="True" />
        <Setter Property="ItemTemplateSelector">
            <Setter.Value>
                <selector:PropertyInfoTypeDataTemplateSelector>
                    <selector:SelectorDataTemplate Key="String">
                        <Grid Style="{StaticResource PropertyViewerGridStyle}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" SharedSizeGroup="PropertyViewerName" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="{Binding PropertyName}" Style="{StaticResource PropertyViewLabelHeaderStyle}" />
                            <TextBox Grid.Column="1" Text="{Binding Value, Mode=TwoWay}" IsEnabled="{Binding IsReadOnly, Converter={StaticResource NotConverter}}" />
                        </Grid>
                    </selector:SelectorDataTemplate>
                    <selector:SelectorDataTemplate Key="Boolean">
                        <Grid Style="{StaticResource PropertyViewerGridStyle}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" SharedSizeGroup="PropertyViewerName" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="{Binding PropertyName}" Style="{StaticResource PropertyViewLabelHeaderStyle}" />
                            <CheckBox Style="{StaticResource PropertyViewElementStyle}" Grid.Column="1" IsChecked="{Binding Value, Mode=TwoWay}" IsEnabled="{Binding IsReadOnly, Converter={StaticResource NotConverter}}" />
                        </Grid>
                    </selector:SelectorDataTemplate>
                    <selector:SelectorDataTemplate Key="Enum">
                        <Grid  Style="{StaticResource PropertyViewerGridStyle}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" SharedSizeGroup="PropertyViewerName" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="{Binding PropertyName}" Style="{StaticResource PropertyViewLabelHeaderStyle}" />
                            <ComboBox Grid.Column="1" ItemsSource="{Binding Value, Converter={StaticResource EnumValuesConverter}}"  SelectedItem="{Binding Value, Mode=TwoWay}" IsEnabled="{Binding IsReadOnly, Converter={StaticResource NotConverter}}" />
                        </Grid>
                    </selector:SelectorDataTemplate>
                    <selector:SelectorDataTemplate Key="Percent">
                        <Grid  Style="{StaticResource PropertyViewerGridStyle}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" SharedSizeGroup="PropertyViewerName" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto" />
                                <RowDefinition Height="auto" />
                            </Grid.RowDefinitions>
                            <TextBlock Text="{Binding PropertyName}" Style="{StaticResource PropertyViewLabelHeaderStyle}" />
                            <StackPanel Orientation="Horizontal" Grid.Column="1">
                                <TextBlock Text=": " Style="{StaticResource PropertyViewLabelHeaderStyle}" />
                                <TextBlock Text="{Binding Value, StringFormat=\{0:N\}}" VerticalAlignment="Center" />
                            </StackPanel> 
                            <Slider Margin="5" Minimum="0" Maximum="1" Grid.ColumnSpan="2" Grid.Row="1" Value="{Binding Value, Mode=TwoWay}" IsEnabled="{Binding IsReadOnly, Converter={StaticResource NotConverter}}" />
                        </Grid>
                    </selector:SelectorDataTemplate>
                </selector:PropertyInfoTypeDataTemplateSelector>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:PropertyViewer}">
                    <ItemsControl x:Name="PART_PropertyContainer"  Grid.IsSharedSizeScope="True" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>